package com.dinzeer.sjapadder.se;

import com.dinzeer.legendreliclib.effect.LReffect;
import com.dinzeer.legendreliclib.lib.compat.slashblade.Drives;
import com.dinzeer.legendreliclib.lib.util.slashblade.SlashBladeUtil;
import com.dinzeer.sjapadder.register.SjaStacksReg;
import mods.flammpfeil.slashblade.entity.EntityDrive;
import mods.flammpfeil.slashblade.item.ItemSlashBlade;
import mods.flammpfeil.slashblade.registry.SpecialEffectsRegistry;
import mods.flammpfeil.slashblade.registry.specialeffects.SpecialEffect;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

import java.util.List;
@Mod.EventBusSubscriber
public class AgitosEX extends Agitos{

    @SubscribeEvent
    public static void onHitEntity(LivingHurtEvent event) {
        if (event.getSource().getEntity() instanceof LivingEntity attacker) {
            if (attacker.getMainHandItem().getItem() instanceof ItemSlashBlade) {
                List<ResourceLocation> effects = SlashBladeUtil.getState(attacker.getMainHandItem()).getSpecialEffects();

                for (ResourceLocation effectId : effects) {
                    SpecialEffect effect = SpecialEffectsRegistry.REGISTRY.get().getValue(effectId);
                    if (effect instanceof AgitosEX agitosEffect) {

                        agitosEffect.handleAgitosEffect(event, attacker);
                    }
                }
            }
        }
    }

    private void handleAgitosEffect(LivingHurtEvent event, LivingEntity attacker) {

        if (attacker instanceof Player player){
            if (!(event.getSource().getDirectEntity() instanceof EntityDrive)){
        SjaStacksReg.BoostTrigger.addStacks(player,1);
            }
            event.setAmount(event.getAmount()*(1+(0.015f*SjaStacksReg.BoostTrigger.getCurrentStacks(player))));
        }

    }

}
